package xmls

var UserMapper = []byte(`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://raw.githubusercontent.com/zhuxiujia/GoMybatis/master/mybatis-3-mapper.dtd">
<mapper>
    <!--logic_enable 逻辑删除字段-->
    <!--logic_deleted 逻辑删除已删除字段-->
    <!--logic_undelete 逻辑删除 未删除字段-->
    <!--version_enable 乐观锁版本字段,支持int,int8,int16,int32,int64-->
    <resultMap id="BaseResultMap" tables="t_user">
      <id column="id" langType="id"/>
	  <result column="username" langType="string"   />
	  <result column="password" langType="string"   />
	  <result column="salt" langType="string"   />
	  <result column="urls" langType="string"   />
	  <result column="is_active" langType="int"/>
	  <result column="create_by" langType="string"   />
	  <result column="create_time" langType="time.Time"   />
	  <result column="update_by" langType="string"   />
	  <result column="update_time" langType="time.Time"   />
	  <result column="is_delete" langType="bool"
			  logic_enable="true"
			  logic_undelete="0"
			  logic_deleted="1"/>
    </resultMap>
	<!--插入模板:默认id="insertTemplate,test="field != null",where自动设置逻辑删除字段,支持批量插入" -->
	<insert id="InsertByUser">
		insert into t_user (  username, password, salt ,is_active,create_by,update_by) values
		( #{username} ,  #{password} ,  #{salt} ,#{is_active},'root','root')
	</insert>
	<!--查询模板:默认id="selectTemplate,where自动设置逻辑删除字段-->
	<selectTemplate wheres="username?username = #{username}"> and is_active !=0</selectTemplate>
	<!--删除模板:默认id="deleteTemplate,where自动设置逻辑删除字段-->
	<deleteTemplate wheres="id?id = #{id}"/>
	<select id="GetUserById">
		select id, username, urls, is_active
		from t_user
		where id = #{id}
		and is_delete = 0
	</select>
	<select id="GetAllUserByPage">
		select id, username, urls, is_active
		from t_user
		where is_delete = 0 
		<if test="value != ''">
			and username like #{'%'+value+'%'}
		</if>
		limit #{current},#{pageSize}
	</select>

	<select id="CountUsers">
		select count(1) from t_user where is_delete = 0
		<if test="value != ''">
			and username like #{'%'+value+'%'}
		</if>
	</select>

	<select id="GetUserByUserName">
		select id, username, urls, is_active
		from t_user where username = #{username} and is_delete =0
	</select>

	<update id="ChangeStatus">
		update t_user set is_active=#{is_active},update_time = current_timestamp where id = #{id}
	</update>

	<update id='UpdatePasswordByUsername'>
		update t_user set password=#{password},salt=#{salt},update_time = current_timestamp where username = #{username}
	</update>
	<select id='GetAllUser'>
		select id, username
		from t_user
		where is_delete = 0
	</select>
</mapper>`)
